using System;
using Comdiv.Extensions;
using Comdiv.Model;
using Comdiv.Model.Interfaces;
using Comdiv.Logging;
using Comdiv.Application;
using Comdiv.Persistence;
using Comdiv.Inversion;
using Comdiv.Security.Acl;
using Comdiv.Conversations;
using Comdiv.IO;
using Comdiv.Security;
using System.Linq;

namespace Comdiv.Doc{
    public class CheckDescendantsStep : DocumentProcessorStep<CheckDescendantsStep>
    {
        private ILog log = logger.get<CheckDescendantsStep>();
        protected override void internalProcess(DocumentQuery query){
            MyQuery = query;
            foreach (var type in MyQuery.ConfiguredTypes){
                foreach (var inttype in type.GetInterfaces()){
                    configure(type, inttype);    
                }
                configure(type, type.BaseType);
            }
        }

        private void configure(Type currentType, Type baseType){
            if(MyQuery.ConfiguredTypes.Contains(baseType)){
                log.Info("{0} is ancestor of {1}",baseType.FullName,currentType.FullName);
                MyQuery[baseType].Descendants.Add(currentType);
            }
        }
    }
}